home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE2 / PD / VINCE / !ViNCe / h / rfbproto < prev    next >
Text File  |  2002-06-30  |  27KB  |  814 lines

  1. /*
  2.  *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
  3.  *
  4.  *  This is free software; you can redistribute it and/or modify
  5.  *  it under the terms of the GNU General Public License as published by
  6.  *  the Free Software Foundation; either version 2 of the License, or
  7.  *  (at your option) any later version.
  8.  *
  9.  *  This software is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *  GNU General Public License for more details.
  13.  *
  14.  *  You should have received a copy of the GNU General Public License
  15.  *  along with this software; if not, write to the Free Software
  16.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  17.  *  USA.
  18.  */
  19.  
  20. /*
  21.  * rfbproto.h - header file for the RFB protocol version 3.3
  22.  *
  23.  * Uses types CARD<n> for an n-bit unsigned integer, INT<n> for an n-bit signed
  24.  * integer (for n = 8, 16 and 32).
  25.  *
  26.  * All multiple byte integers are in big endian (network) order (most
  27.  * significant byte first).  Unless noted otherwise there is no special
  28.  * alignment of protocol structures.
  29.  *
  30.  *
  31.  * Once the initial handshaking is done, all messages start with a type byte,
  32.  * (usually) followed by message-specific data.  The order of definitions in
  33.  * this file is as follows:
  34.  *
  35.  *  (1) Structures used in several types of message.
  36.  *  (2) Structures used in the initial handshaking.
  37.  *  (3) Message types.
  38.  *  (4) Encoding types.
  39.  *  (5) For each message type, the form of the data following the type byte.
  40.  *      Sometimes this is defined by a single structure but the more complex
  41.  *      messages have to be explained by comments.
  42.  */
  43.  
  44.  
  45. /*****************************************************************************
  46.  *
  47.  * Structures used in several messages
  48.  *
  49.  *****************************************************************************/
  50.  
  51. /*-----------------------------------------------------------------------------
  52.  * Structure used to specify a rectangle.  This structure is a multiple of 4
  53.  * bytes so that it can be interspersed with 32-bit pixel data without
  54.  * affecting alignment.
  55.  */
  56.  
  57. typedef unsigned char  CARD8;
  58. typedef unsigned short CARD16;
  59. typedef unsigned int   CARD32;
  60. typedef signed char    INT8;
  61. typedef signed short   INT16;
  62. typedef signed int     INT32;
  63. typedef int            Bool;
  64. typedef char *         String;
  65. #define True        1
  66. #define False       0
  67.  
  68. typedef struct {
  69.     CARD16 x;
  70.     CARD16 y;
  71.     CARD16 w;
  72.     CARD16 h;
  73. } rfbRectangle;
  74.  
  75. #define sz_rfbRectangle 8
  76.  
  77.  
  78. /*-----------------------------------------------------------------------------
  79.  * Structure used to specify pixel format.
  80.  */
  81.  
  82. typedef struct {
  83.  
  84.     CARD8 bitsPerPixel;        /* 8,16,32 only */
  85.  
  86.     CARD8 depth;        /* 8 to 32 */
  87.  
  88.     CARD8 bigEndian;        /* True if multi-byte pixels are interpreted
  89.                    as big endian, or if single-bit-per-pixel
  90.                    has most significant bit of the byte
  91.                    corresponding to first (leftmost) pixel. Of
  92.                    course this is meaningless for 8 bits/pix */
  93.  
  94.     CARD8 trueColour;        /* If false then we need a "colour map" to
  95.                    convert pixels to RGB.  If true, xxxMax and
  96.                    xxxShift specify bits used for red, green
  97.                    and blue */
  98.  
  99.     /* the following fields are only meaningful if trueColour is true */
  100.  
  101.     CARD16 redMax;        /* maximum red value (= 2^n - 1 where n is the
  102.                    number of bits used for red). Note this
  103.                    value is always in big endian order. */
  104.  
  105.     CARD16 greenMax;        /* similar for green */
  106.  
  107.     CARD16 blueMax;        /* and blue */
  108.  
  109.     CARD8 redShift;        /* number of shifts needed to get the red
  110.                    value in a pixel to the least significant
  111.                    bit. To find the red value from a given
  112.                    pixel, do the following:
  113.                    1) Swap pixel value according to bigEndian
  114.                       (e.g. if bigEndian is false and host byte
  115.                       order is big endian, then swap).
  116.                    2) Shift right by redShift.
  117.                    3) AND with redMax (in host byte order).
  118.                    4) You now have the red value between 0 and
  119.                       redMax. */
  120.  
  121.     CARD8 greenShift;        /* similar for green */
  122.  
  123.     CARD8 blueShift;        /* and blue */
  124.  
  125.     CARD8 pad1;
  126.     CARD16 pad2;
  127.  
  128. } rfbPixelFormat;
  129.  
  130. #define sz_rfbPixelFormat 16
  131.  
  132.  
  133.  
  134. /*****************************************************************************
  135.  *
  136.  * Initial handshaking messages
  137.  *
  138.  *****************************************************************************/
  139.  
  140. /*-----------------------------------------------------------------------------
  141.  * Protocol Version
  142.  *
  143.  * The server always sends 12 bytes to start which identifies the latest RFB
  144.  * protocol version number which it supports.  These bytes are interpreted
  145.  * as a string of 12 ASCII characters in the format "RFB xxx.yyy\n" where
  146.  * xxx and yyy are the major and minor version numbers (for version 3.3
  147.  * this is "RFB 003.003\n").
  148.  *
  149.  * The client then replies with a similar 12-byte message giving the version
  150.  * number of the protocol which should actually be used (which may be different
  151.  * to that quoted by the server).
  152.  *
  153.  * It is intended that both clients and servers may provide some level of
  154.  * backwards compatibility by this mechanism.  Servers in particular should
  155.  * attempt to provide backwards compatibility, and even forwards compatibility
  156.  * to some extent.  For example if a client demands version 3.1 of the
  157.  * protocol, a 3.0 server can probably assume that by ignoring requests for
  158.  * encoding types it doesn't understand, everything will still work OK.  This
  159.  * will probably not be the case for changes in the major version number.
  160.  *
  161.  * The format string below can be used in sprintf or sscanf to generate or
  162.  * decode the version string respectively.
  163.  */
  164.  
  165. #define rfbProtocolVersionFormat "RFB %03d.%03d\n"
  166. #define rfbProtocolMajorVersion 3
  167. #define rfbProtocolMinorVersion 3
  168.  
  169. typedef char rfbProtocolVersionMsg[13];    /* allow extra byte for null */
  170.  
  171. #define sz_rfbProtocolVersionMsg 12
  172.  
  173.  
  174. /*-----------------------------------------------------------------------------
  175.  * Authentication
  176.  *
  177.  * Once the protocol version has been decided, the server then sends a 32-bit
  178.  * word indicating whether any authentication is needed on the connection.
  179.  * The value of this word determines the authentication scheme in use.  For
  180.  * version 3.0 of the protocol this may have one of the following values:
  181.  */
  182.  
  183. #define rfbConnFailed 0
  184. #define rfbNoAuth 1
  185. #define rfbVncAuth 2
  186.  
  187. /*
  188.  * rfbConnFailed:    For some reason the connection failed (e.g. the server
  189.  *            cannot support the desired protocol version).  This is
  190.  *            followed by a string describing the reason (where a
  191.  *            string is specified as a 32-bit length followed by that
  192.  *            many ASCII characters).
  193.  *
  194.  * rfbNoAuth:        No authentication is needed.
  195.  *
  196.  * rfbVncAuth:        The VNC authentication scheme is to be used.  A 16-byte
  197.  *            challenge follows, which the client encrypts as
  198.  *            appropriate using the password and sends the resulting
  199.  *            16-byte response.  If the response is correct, the
  200.  *            server sends the 32-bit word rfbVncAuthOK.  If a simple
  201.  *            failure happens, the server sends rfbVncAuthFailed and
  202.  *            closes the connection. If the server decides that too
  203.  *            many failures have occurred, it sends rfbVncAuthTooMany
  204.  *            and closes the connection.  In the latter case, the
  205.  *            server should not allow an immediate reconnection by
  206.  *            the client.
  207.  */
  208.  
  209. #define rfbVncAuthOK 0
  210. #define rfbVncAuthFailed 1
  211. #define rfbVncAuthTooMany 2
  212.  
  213.  
  214. /*-----------------------------------------------------------------------------
  215.  * Client Initialisation Message
  216.  *
  217.  * Once the client and server are sure that they're happy to talk to one
  218.  * another, the client sends an initialisation message.  At present this
  219.  * message only consists of a boolean indicating whether the server should try
  220.  * to share the desktop by leaving other clients connected, or give exclusive
  221.  * access to this client by disconnecting all other clients.
  222.  */
  223.  
  224. typedef struct {
  225.     CARD8 shared;
  226. } rfbClientInitMsg;
  227.  
  228. #define sz_rfbClientInitMsg 1
  229.  
  230.  
  231. /*-----------------------------------------------------------------------------
  232.  * Server Initialisation Message
  233.  *
  234.  * After the client initialisation message, the server sends one of its own.
  235.  * This tells the client the width and height of the server's framebuffer,
  236.  * its pixel format and the name associated with the desktop.
  237.  */
  238.  
  239. typedef struct {
  240.     CARD16 framebufferWidth;
  241.     CARD16 framebufferHeight;
  242.     rfbPixelFormat format;    /* the server's preferred pixel format */
  243.     CARD32 nameLength;
  244.     /* followed by char name[nameLength] */
  245. } rfbServerInitMsg;
  246.  
  247. #define sz_rfbServerInitMsg (8 + sz_rfbPixelFormat)
  248.  
  249.  
  250. /*
  251.  * Following the server initialisation message it's up to the client to send
  252.  * whichever protocol messages it wants.  Typically it will send a
  253.  * SetPixelFormat message and a SetEncodings message, followed by a
  254.  * FramebufferUpdateRequest.  From then on the server will send
  255.  * FramebufferUpdate messages in response to the client's
  256.  * FramebufferUpdateRequest messages.  The client should send
  257.  * FramebufferUpdateRequest messages with incremental set to true when it has
  258.  * finished processing one FramebufferUpdate and is ready to process another.
  259.  * With a fast client, the rate at which FramebufferUpdateRequests are sent
  260.  * should be regulated to avoid hogging the network.
  261.  */
  262.  
  263.  
  264.  
  265. /*****************************************************************************
  266.  *
  267.  * Message types
  268.  *
  269.  *****************************************************************************/
  270.  
  271. /* server -> client */
  272.  
  273. #define rfbFramebufferUpdate 0
  274. #define rfbSetColourMapEntries 1
  275. #define rfbBell 2
  276. #define rfbServerCutText 3
  277.  
  278.  
  279. /* client -> server */
  280.  
  281. #define rfbSetPixelFormat 0
  282. #define rfbFixColourMapEntries 1    /* not currently supported */
  283. #define rfbSetEncodings 2
  284. #define rfbFramebufferUpdateRequest 3
  285. #define rfbKeyEvent 4
  286. #define rfbPointerEvent 5
  287. #define rfbClientCutText 6
  288.  
  289.  
  290.  
  291.  
  292. /*****************************************************************************
  293.  *
  294.  * Encoding types
  295.  *
  296.  *****************************************************************************/
  297.  
  298. #define rfbEncodingRaw 0
  299. #define rfbEncodingCopyRect 1
  300. #define rfbEncodingRRE 2
  301. #define rfbEncodingCoRRE 4
  302. #define rfbEncodingZlib 6
  303. #define rfbEncodingHextile 5
  304. #define rfbEncodingTight 7
  305. #define rfbEncodingZlibHex 8
  306. #define rfbEncodingCheckClientBitmap    0x00220000
  307. #define rfbEncodingHextileDither8       0x00221000
  308.  
  309. /*
  310.  * Special encoding numbers:
  311.  *   0xFFFFFF00 .. 0xFFFFFF0F -- encoding-specific compression levels;
  312.  *   0xFFFFFF10 .. 0xFFFFFF1F -- mouse cursor shape data;
  313.  *   0xFFFFFF20 .. 0xFFFFFF2F -- various protocol extensions;
  314.  *   0xFFFFFF30 .. 0xFFFFFFDF -- not allocated yet;
  315.  *   0xFFFFFFE0 .. 0xFFFFFFEF -- quality level for JPEG compressor;
  316.  *   0xFFFFFFF0 .. 0xFFFFFFFF -- cross-encoding compression levels.
  317.  */
  318.  
  319. #define rfbEncodingCompressLevel0  0xFFFFFF00
  320. #define rfbEncodingCompressLevel1  0xFFFFFF01
  321. #define rfbEncodingCompressLevel2  0xFFFFFF02
  322. #define rfbEncodingCompressLevel3  0xFFFFFF03
  323. #define rfbEncodingCompressLevel4  0xFFFFFF04
  324. #define rfbEncodingCompressLevel5  0xFFFFFF05
  325. #define rfbEncodingCompressLevel6  0xFFFFFF06
  326. #define rfbEncodingCompressLevel7  0xFFFFFF07
  327. #define rfbEncodingCompressLevel8  0xFFFFFF08
  328. #define rfbEncodingCompressLevel9  0xFFFFFF09
  329.  
  330. #define rfbEncodingXCursor         0xFFFFFF10
  331. #define rfbEncodingRichCursor      0xFFFFFF11
  332.  
  333. #define rfbEncodingLastRect        0xFFFFFF20
  334.  
  335. #define rfbEncodingQualityLevel0   0xFFFFFFE0
  336. #define rfbEncodingQualityLevel1   0xFFFFFFE1
  337. #define rfbEncodingQualityLevel2   0xFFFFFFE2
  338. #define rfbEncodingQualityLevel3   0xFFFFFFE3
  339. #define rfbEncodingQualityLevel4   0xFFFFFFE4
  340. #define rfbEncodingQualityLevel5   0xFFFFFFE5
  341. #define rfbEncodingQualityLevel6   0xFFFFFFE6
  342. #define rfbEncodingQualityLevel7   0xFFFFFFE7
  343. #define rfbEncodingQualityLevel8   0xFFFFFFE8
  344. #define rfbEncodingQualityLevel9   0xFFFFFFE9
  345.  
  346.  
  347.  
  348. /*****************************************************************************
  349.  *
  350.  * Server -> client message definitions
  351.  *
  352.  *****************************************************************************/
  353.  
  354.  
  355. /*-----------------------------------------------------------------------------
  356.  * FramebufferUpdate - a block of rectangles to be copied to the framebuffer.
  357.  *
  358.  * This message consists of a header giving the number of rectangles of pixel
  359.  * data followed by the rectangles themselves.  The header is padded so that
  360.  * together with the type byte it is an exact multiple of 4 bytes (to help
  361.  * with alignment of 32-bit pixels):
  362.  */
  363.  
  364. typedef struct {
  365.     CARD8 type;            /* always rfbFramebufferUpdate */
  366.     CARD8 pad;
  367.     CARD16 nRects;
  368.     /* followed by nRects rectangles */
  369. } rfbFramebufferUpdateMsg;
  370.  
  371. #define sz_rfbFramebufferUpdateMsg 4
  372.  
  373. /*
  374.  * Each rectangle of pixel data consists of a header describing the position
  375.  * and size of the rectangle and a type word describing the encoding of the
  376.  * pixel data, followed finally by the pixel data.  Note that if the client has
  377.  * not sent a SetEncodings message then it will only receive raw pixel data.
  378.  * Also note again that this structure is a multiple of 4 bytes.
  379.  */
  380.  
  381. typedef struct {
  382.     rfbRectangle r;
  383.     CARD32 encoding;    /* one of the encoding types rfbEncoding... */
  384. } rfbFramebufferUpdateRectHeader;
  385.  
  386. #define sz_rfbFramebufferUpdateRectHeader (sz_rfbRectangle + 4)
  387.  
  388.  
  389. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  390.  * Raw Encoding.  Pixels are sent in top-to-bottom scanline order,
  391.  * left-to-right within a scanline with no padding in between.
  392.  */
  393.  
  394.  
  395. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  396.  * CopyRect Encoding.  The pixels are specified simply by the x and y position
  397.  * of the source rectangle.
  398.  */
  399.  
  400. typedef struct {
  401.     CARD16 srcX;
  402.     CARD16 srcY;
  403. } rfbCopyRect;
  404.  
  405. #define sz_rfbCopyRect 4
  406.  
  407.  
  408. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  409.  * RRE - Rise-and-Run-length Encoding.  We have an rfbRREHeader structure
  410.  * giving the number of subrectangles following.  Finally the data follows in
  411.  * the form [<bgpixel><subrect><subrect>...] where each <subrect> is
  412.  * [<pixel><rfbRectangle>].
  413.  */
  414.  
  415. typedef struct {
  416.     CARD32 nSubrects;
  417. } rfbRREHeader;
  418.  
  419. #define sz_rfbRREHeader 4
  420.  
  421.  
  422. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  423.  * CoRRE - Compact RRE Encoding.  We have an rfbRREHeader structure giving
  424.  * the number of subrectangles following.  Finally the data follows in the form
  425.  * [<bgpixel><subrect><subrect>...] where each <subrect> is
  426.  * [<pixel><rfbCoRRERectangle>].  This means that
  427.  * the whole rectangle must be at most 255x255 pixels.
  428.  */
  429.  
  430. typedef struct {
  431.     CARD8 x;
  432.     CARD8 y;
  433.     CARD8 w;
  434.     CARD8 h;
  435. } rfbCoRRERectangle;
  436.  
  437. #define sz_rfbCoRRERectangle 4
  438.  
  439.  
  440. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  441.  * Hextile Encoding.  The rectangle is divided up into "tiles" of 16x16 pixels,
  442.  * starting at the top left going in left-to-right, top-to-bottom order.  If
  443.  * the width of the rectangle is not an exact multiple of 16 then the width of
  444.  * the last tile in each row will be correspondingly smaller.  Similarly if the
  445.  * height is not an exact multiple of 16 then the height of each tile in the
  446.  * final row will also be smaller.  Each tile begins with a "subencoding" type
  447.  * byte, which is a mask made up of a number of bits.  If the Raw bit is set
  448.  * then the other bits are irrelevant; w*h pixel values follow (where w and h
  449.  * are the width and height of the tile).  Otherwise the tile is encoded in a
  450.  * similar way to RRE, except that the position and size of each subrectangle
  451.  * can be specified in just two bytes.  The other bits in the mask are as
  452.  * follows:
  453.  *
  454.  * BackgroundSpecified - if set, a pixel value follows which specifies
  455.  *    the background colour for this tile.  The first non-raw tile in a
  456.  *    rectangle must have this bit set.  If this bit isn't set then the
  457.  *    background is the same as the last tile.
  458.  *
  459.  * ForegroundSpecified - if set, a pixel value follows which specifies
  460.  *    the foreground colour to be used for all subrectangles in this tile.
  461.  *    If this bit is set then the SubrectsColoured bit must be zero.
  462.  *
  463.  * AnySubrects - if set, a single byte follows giving the number of
  464.  *    subrectangles following.  If not set, there are no subrectangles (i.e.
  465.  *    the whole tile is just solid background colour).
  466.  *
  467.  * SubrectsColoured - if set then each subrectangle is preceded by a pixel
  468.  *    value giving the colour of that subrectangle.  If not set, all
  469.  *    subrectangles are the same colour, the foreground colour;  if the
  470.  *    ForegroundSpecified bit wasn't set then the foreground is the same as
  471.  *    the last tile.
  472.  *
  473.  * The position and size of each subrectangle is specified in two bytes.  The
  474.  * Pack macros below can be used to generate the two bytes from x, y, w, h,
  475.  * and the Extract macros can be used to extract the x, y, w, h values from
  476.  * the two bytes.
  477.  */
  478.  
  479. #define rfbHextileRaw            (1 << 0)
  480. #define rfbHextileRawDither            (1 << 4)
  481. #define rfbHextileBackgroundSpecified    (1 << 1)
  482. #define rfbHextileForegroundSpecified    (1 << 2)
  483. #define rfbHextileAnySubrects        (1 << 3)
  484. #define rfbHextileSubrectsColoured    (1 << 4)
  485.  
  486. #define rfbHextilePackXY(x,y) (((x) << 4) | (y))
  487. #define rfbHextilePackWH(w,h) ((((w)-1) << 4) | ((h)-1))
  488. #define rfbHextileExtractX(byte) ((byte) >> 4)
  489. #define rfbHextileExtractY(byte) ((byte) & 0xf)
  490. #define rfbHextileExtractW(byte) (((byte) >> 4) + 1)
  491. #define rfbHextileExtractH(byte) (((byte) & 0xf) + 1)
  492.  
  493. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  494.  * zlib - zlib compressed Encoding.  We have an rfbZlibHeader structure
  495.  * giving the number of bytes following.  Finally the data follows is
  496.  * zlib compressed version of the raw pixel data as negotiated.
  497.  */
  498.  
  499. typedef struct {
  500.     CARD32 nBytes;
  501. } rfbZlibHeader;
  502.  
  503. #define sz_rfbZlibHeader 4
  504.  
  505.  
  506. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  507.  * ``Tight'' Encoding.  FIXME: Add more documentation.
  508.  */
  509.  
  510. #define rfbTightExplicitFilter         0x04
  511. #define rfbTightFill                   0x08
  512. #define rfbTightJpeg                   0x09
  513. #define rfbTightMaxSubencoding         0x09
  514.  
  515. /* Filters to improve compression efficiency */
  516. #define rfbTightFilterCopy             0x00
  517. #define rfbTightFilterPalette          0x01
  518. #define rfbTightFilterGradient         0x02
  519.  
  520. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  521.  * XCursor encoding. This is a special encoding used to transmit X-style
  522.  * cursor shapes from server to clients. Note that for this encoding,
  523.  * coordinates in rfbFramebufferUpdateRectHeader structure hold hotspot
  524.  * position (r.x, r.y) and cursor size (r.w, r.h). If (w * h != 0), two RGB
  525.  * samples are sent after header in the rfbXCursorColors structure. They
  526.  * denote foreground and background colors of the cursor. If a client
  527.  * supports only black-and-white cursors, it should ignore these colors and
  528.  * assume that foreground is black and background is white. Next, two bitmaps
  529.  * (1 bits per pixel) follow: first one with actual data (value 0 denotes
  530.  * background color, value 1 denotes foreground color), second one with
  531.  * transparency data (bits with zero value mean that these pixels are
  532.  * transparent). Both bitmaps represent cursor data in a byte stream, from
  533.  * left to right, from top to bottom, and each row is byte-aligned. Most
  534.  * significant bits correspond to leftmost pixels. The number of bytes in
  535.  * each row can be calculated as ((w + 7) / 8). If (w * h == 0), cursor
  536.  * should be hidden (or default local cursor should be set by the client).
  537.  */
  538.  
  539. typedef struct {
  540.     CARD8 foreRed;
  541.     CARD8 foreGreen;
  542.     CARD8 foreBlue;
  543.     CARD8 backRed;
  544.     CARD8 backGreen;
  545.     CARD8 backBlue;
  546. } rfbXCursorColors;
  547.  
  548. #define sz_rfbXCursorColors 6
  549.  
  550.  
  551. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  552.  * RichCursor encoding. This is a special encoding used to transmit cursor
  553.  * shapes from server to clients. It is similar to the XCursor encoding but
  554.  * uses client pixel format instead of two RGB colors to represent cursor
  555.  * image. For this encoding, coordinates in rfbFramebufferUpdateRectHeader
  556.  * structure hold hotspot position (r.x, r.y) and cursor size (r.w, r.h).
  557.  * After header, two pixmaps follow: first one with cursor image in current
  558.  * client pixel format (like in raw encoding), second with transparency data
  559.  * (1 bit per pixel, exactly the same format as used for transparency bitmap
  560.  * in the XCursor encoding). If (w * h == 0), cursor should be hidden (or
  561.  * default local cursor should be set by the client).
  562.  */
  563.  
  564. /*-----------------------------------------------------------------------------
  565.  * SetColourMapEntries - these messages are only sent if the pixel
  566.  * format uses a "colour map" (i.e. trueColour false) and the client has not
  567.  * fixed the entire colour map using FixColourMapEntries.  In addition they
  568.  * will only start being sent after the client has sent its first
  569.  * FramebufferUpdateRequest.  So if the client always tells the server to use
  570.  * trueColour then it never needs to process this type of message.
  571.  */
  572.  
  573. typedef struct {
  574.     CARD8 type;            /* always rfbSetColourMapEntries */
  575.     CARD8 pad;
  576.     CARD16 firstColour;
  577.     CARD16 nColours;
  578.  
  579.     /* Followed by nColours * 3 * CARD16
  580.        r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
  581.  
  582. } rfbSetColourMapEntriesMsg;
  583.  
  584. #define sz_rfbSetColourMapEntriesMsg 6
  585.  
  586.  
  587.  
  588. /*-----------------------------------------------------------------------------
  589.  * Bell - ring a bell on the client if it has one.
  590.  */
  591.  
  592. typedef struct {
  593.     CARD8 type;            /* always rfbBell */
  594. } rfbBellMsg;
  595.  
  596. #define sz_rfbBellMsg 1
  597.  
  598.  
  599.  
  600. /*-----------------------------------------------------------------------------
  601.  * ServerCutText - the server has new text in its cut buffer.
  602.  */
  603.  
  604. typedef struct {
  605.     CARD8 type;            /* always rfbServerCutText */
  606.     CARD8 pad1;
  607.     CARD16 pad2;
  608.     CARD32 length;
  609.     /* followed by char text[length] */
  610. } rfbServerCutTextMsg;
  611.  
  612. #define sz_rfbServerCutTextMsg 8
  613.  
  614.  
  615. /*-----------------------------------------------------------------------------
  616.  * Union of all server->client messages.
  617.  */
  618.  
  619. typedef union {
  620.     CARD8 type;
  621.     rfbFramebufferUpdateMsg fu;
  622.     rfbSetColourMapEntriesMsg scme;
  623.     rfbBellMsg b;
  624.     rfbServerCutTextMsg sct;
  625. } rfbServerToClientMsg;
  626.  
  627.  
  628.  
  629. /*****************************************************************************
  630.  *
  631.  * Message definitions (client -> server)
  632.  *
  633.  *****************************************************************************/
  634.  
  635.  
  636. /*-----------------------------------------------------------------------------
  637.  * SetPixelFormat - tell the RFB server the format in which the client wants
  638.  * pixels sent.
  639.  */
  640.  
  641. typedef struct {
  642.     CARD8 type;            /* always rfbSetPixelFormat */
  643.     CARD8 pad1;
  644.     CARD16 pad2;
  645.     rfbPixelFormat format;
  646. } rfbSetPixelFormatMsg;
  647.  
  648. #define sz_rfbSetPixelFormatMsg (sz_rfbPixelFormat + 4)
  649.  
  650.  
  651. /*-----------------------------------------------------------------------------
  652.  * FixColourMapEntries - when the pixel format uses a "colour map", fix
  653.  * read-only colour map entries.
  654.  *
  655.  *    ***************** NOT CURRENTLY SUPPORTED *****************
  656.  */
  657.  
  658. typedef struct {
  659.     CARD8 type;            /* always rfbFixColourMapEntries */
  660.     CARD8 pad;
  661.     CARD16 firstColour;
  662.     CARD16 nColours;
  663.  
  664.     /* Followed by nColours * 3 * CARD16
  665.        r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */
  666.  
  667. } rfbFixColourMapEntriesMsg;
  668.  
  669. #define sz_rfbFixColourMapEntriesMsg 6
  670.  
  671.  
  672. /*-----------------------------------------------------------------------------
  673.  * SetEncodings - tell the RFB server which encoding types we accept.  Put them
  674.  * in order of preference, if we have any.  We may always receive raw
  675.  * encoding, even if we don't specify it here.
  676.  */
  677.  
  678. typedef struct {
  679.     CARD8 type;            /* always rfbSetEncodings */
  680.     CARD8 pad;
  681.     CARD16 nEncodings;
  682.     /* followed by nEncodings * CARD32 encoding types */
  683. } rfbSetEncodingsMsg;
  684.  
  685. #define sz_rfbSetEncodingsMsg 4
  686.  
  687.  
  688. /*-----------------------------------------------------------------------------
  689.  * FramebufferUpdateRequest - request for a framebuffer update.  If incremental
  690.  * is true then the client just wants the changes since the last update.  If
  691.  * false then it wants the whole of the specified rectangle.
  692.  */
  693.  
  694. typedef struct {
  695.     CARD8 type;            /* always rfbFramebufferUpdateRequest */
  696.     CARD8 incremental;
  697.     CARD16 x;
  698.     CARD16 y;
  699.     CARD16 w;
  700.     CARD16 h;
  701. } rfbFramebufferUpdateRequestMsg;
  702.  
  703. #define sz_rfbFramebufferUpdateRequestMsg 10
  704.  
  705.  
  706. /*-----------------------------------------------------------------------------
  707.  * KeyEvent - key press or release
  708.  *
  709.  * Keys are specified using the "keysym" values defined by the X Window System.
  710.  * For most ordinary keys, the keysym is the same as the corresponding ASCII
  711.  * value.  Other common keys are:
  712.  *
  713.  * BackSpace        0xff08
  714.  * Tab            0xff09
  715.  * Return or Enter    0xff0d
  716.  * Escape        0xff1b
  717.  * Insert        0xff63
  718.  * Delete        0xffff
  719.  * Home            0xff50
  720.  * End            0xff57
  721.  * Page Up        0xff55
  722.  * Page Down        0xff56
  723.  * Left            0xff51
  724.  * Up            0xff52
  725.  * Right        0xff53
  726.  * Down            0xff54
  727.  * F1            0xffbe
  728.  * F2            0xffbf
  729.  * ...            ...
  730.  * F12            0xffc9
  731.  * Shift        0xffe1
  732.  * Control        0xffe3
  733.  * Meta            0xffe7
  734.  * Alt            0xffe9
  735.  */
  736.  
  737. typedef struct {
  738.     CARD8 type;            /* always rfbKeyEvent */
  739.     CARD8 down;            /* true if down (press), false if up */
  740.     CARD16 pad;
  741.     CARD32 key;            /* key is specified as an X keysym */
  742. } rfbKeyEventMsg;
  743.  
  744. #define sz_rfbKeyEventMsg 8
  745.  
  746.  
  747. /*-----------------------------------------------------------------------------
  748.  * PointerEvent - mouse/pen move and/or button press.
  749.  */
  750.  
  751. typedef struct {
  752.     CARD8 type;            /* always rfbPointerEvent */
  753.     CARD8 buttonMask;        /* bits 0-7 are buttons 1-8, 0=up, 1=down */
  754.     CARD16 x;
  755.     CARD16 y;
  756. } rfbPointerEventMsg;
  757.  
  758. #define rfbButton1Mask 1
  759. #define rfbButton2Mask 2
  760. #define rfbButton3Mask 4
  761.  
  762. #define sz_rfbPointerEventMsg 6
  763.  
  764.  
  765.  
  766. /*-----------------------------------------------------------------------------
  767.  * ClientCutText - the client has new text in its cut buffer.
  768.  */
  769.  
  770. typedef struct {
  771.     CARD8 type;            /* always rfbClientCutText */
  772.     CARD8 pad1;
  773.     CARD16 pad2;
  774.     CARD32 length;
  775.     /* followed by char text[length] */
  776. } rfbClientCutTextMsg;
  777.  
  778. #define sz_rfbClientCutTextMsg 8
  779.  
  780.  
  781.  
  782. /*-----------------------------------------------------------------------------
  783.  * Union of all client->server messages.
  784.  */
  785.  
  786. typedef union {
  787.     CARD8 type;
  788.     rfbSetPixelFormatMsg spf;
  789.     rfbFixColourMapEntriesMsg fcme;
  790.     rfbSetEncodingsMsg se;
  791.     rfbFramebufferUpdateRequestMsg fur;
  792.     rfbKeyEventMsg ke;
  793.     rfbPointerEventMsg pe;
  794.     rfbClientCutTextMsg cct;
  795. } rfbClientToServerMsg;
  796.  
  797.  
  798. /*-----------------------------------------------------------------------------
  799.  * Sound related defines
  800.  */
  801.  
  802. #define VNC_SOUND_ENABLED_B    (16)
  803. #define VNC_SOUND_STEREO_B    (17)
  804. #define VNC_SOUND_16BIT_B    (18)
  805. #define VNC_SOUND_ADPCM_B    (19)
  806.  
  807. #define VNC_SOUND_ENABLED     (1<<VNC_SOUND_ENABLED_B)
  808. #define VNC_SOUND_MONO      0
  809. #define VNC_SOUND_STEREO      (1<<VNC_SOUND_STEREO_B)
  810. #define VNC_SOUND_16BIT       (1<<VNC_SOUND_16BIT_B)
  811. #define VNC_SOUND_ADPCM       (1<<VNC_SOUND_ADPCM_B)
  812. #define VNC_SOUND_FREQMASK    0x0000FFFF
  813.  
  814.